<?php

/*

  Action - Attack	$4

  +1 Card; +1 Action
  Each player (including you) reveals the top card of his deck and either discards it or puts it back, your choice.

 */

class Spy extends Card implements iAction, iKingdom, iAttack, iBasic {

    public function __construct() {
        parent::__construct("Spy", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }
    
    
    public function getDescription() {
        return array(
            "+1 Card",
            "+1 Action",
            "Each player (including you) reveals the top card of his deck and either discards it or puts it back, your choice.");
    }

    private function helper(Game $game, $name) {
        
        $card = $game->removeCardFromDrawDeck($name);
        if ($card) {
             ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($card), "reveals " . ScreenDisplay::$LMSG, $name);
            $options = array(new Option(1, "Yes"), new Option(2, "No"));
            
            $output = MySocket::GetUserReply($game,  Input_ChooseOne, $options, 1, 1, null, "Discard " . $card->getValue() . " to " . $name . "?");
            if ($output[0] == 'Yes') {
                $game->putCardInDiscardDeck($card, $name);
                  ScreenDisplay::addScreenMessage($game, false, " and discard it"," and discards it",$name);
            } else {
                $game->putCardOnTopOfDrawDeck($card, $name);
                 ScreenDisplay::addScreenMessage($game, false, " and return it on top of your deck"," and returns it on top of his deck",$name);
            }
        }
    }

    public function play(Game $game, $isRealCard) {

        $drawed_cards = $game->drawCards(1);
        $game->addActions(1);
        ScreenDisplay::addScreenMessage($game, true, "get +1 action  and draw ".  nicePrint($drawed_cards), "gets +1 action and draws ".sizeof($drawed_cards). " cards");
        
        $game->attack($this);
        
        $names = $game->getPlayersNames(true);
        foreach ($names as $name) {
            $this->helper($game, $name);
        }
        $game->cardActionFinished();
        return true;
    }
}

?>